<?php

namespace addons\mall\library;

use app\common\library\Auth;
use think\Exception;
use think\Hook;
use think\Request;

class Order
{
    /**
     * 发起订单支付(微信和支付宝)
     * @param string $isBatch
     * @param string $orderNo
     * @param float  $money
     * @param string $paycode
     * @param string $title
     * @throws OrderException
     */
    public static function submit($isBatch, $orderNo, $money, $paycode = 'wechat', $title = '')
    {
        $title = $title ? $title : '支付';

        $epay = get_addon_info('epay');

        if ($epay && $epay['state']) {
            $notifyurl = addon_url('mall/order/epay', [], false, true) . '/type/notify/paycode/' . $paycode;
            $returnurl = addon_url('mall/order/epay', [], false, true) . '/type/return/paycode/' . $paycode;

            \addons\epay\library\Service::submitOrder($money, $orderNo, $paycode, $title, $notifyurl, $returnurl);
        } else {
            $result = Hook::listen('mall_order_submit', $order);
            if (!$result) {
                throw new OrderException("请先在后台安装配置微信支付宝整合插件");
            }
        }
    }

}